import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy, $http } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container-scroll'))
const $cache				= $Lazy.file(()=>import('#private/cache-api'))
const width = 500
// ===================================================================== component
// 新增修改基本资料 20200927 耿琰
class Index extends React.Component{
	state = {
		customHide: true,	// 控制自定义属性显示或隐藏
		// 搜索表单列表
		formData : [
			{ label: '标本条码',		name: 'spec_code', 				width, required:true, readOnly:true },
			{ label: '报告时间',		name: 'report_at', 				width, readOnly:true },
			{ label: '姓名',			name: 'patient_name', 			width, required:true, br:true  },
			{ label: '性别',			name: 'sex',					width, required:true, type:'select',idStr:'code', value:'45703', isKeydown: 'sex' },
			{ label: '证件类型',		name: 'card_type',				width, type:'select', idStr: 'code'},
			{ label: '证件号',		name: 'card_no', 				width, br:true  },
			{ label: '床号',			name: 'bed_no', 				width },
			{ label: '门诊/住院号',	name: 'outpatient', 			width },
			{ label: '送检科室',		name: 'department', 			width, br:true },
			{ label: '送检医生',		name: 'doctor', 				width },
			{ label: '临床诊断',		name: 'diagnosis_info', 		width },
			{ label: '受检人类型',	name: 'case_type', 				width,	type:'select',	idStr: 'code',	isKeydown: 'case_type', br:true },
			{ label: '年龄一',		name: 'age_first_val', 			width },
			{ label: '年龄类型一',	name: 'age_first_type', 		width, required:true, type:'select', idStr: 'code', value: "30001" },
			{ label: '年龄二',		name: 'age_second_val', 		width, br:true },
			{ label: '年龄类型二',	name: 'age_second_type', 		width, required:true, type:'select', idStr: 'code', value: "30003" },
			{ label: '采样时间',		name: 'samp_time', 				width, type:'time' },
			{ label: '采样日期',		name: 'samp_date', 				width, type:'date-time', br:true, format:1 },
			{ label: '接收日期',		name: 'created_at', 			width, type:'date-time', required:true },
			{ label: '采集类型',		name: 'collect_type', 			width, type: 'radio', 	mode:'button'},
			{ label: '医院标识',		name: 'hosp_identification', 	width, br:true },
			{ label: '医生电话',		name: 'doctor_phone', 			width },
			{ label: '受检人电话',	name: 'patient_phone', 			width },
			{ label: '备注',			name: 'remark', 				half:true, type:'textarea', br:true },
			// 病人基本信息 增加5个自定义字段 2021-10-15  --马婷
			{ hide:true,	custom:true, onClick:()=>{this.customClick()}},
			{ label:'备用1', 		name:'user_defined1', 		hide:true,	width, },
			{ label:'备用2', 		name:'user_defined2', 		hide:true,	width, },
			{ label:'备用3', 		name:'user_defined3', 		hide:true,	width, },
			{ label:'备用4', 		name:'user_defined4', 		hide:true,	width, },
			{ label:'备用5', 		name:'user_defined5', 		hide:true,	width, },
			{ label:'备用6', 		name:'user_defined6', 		hide:true,	width, },
			{ label:'备用7', 		name:'user_defined7', 		hide:true,	width, },
			{ label:'备用8', 		name:'user_defined8', 		hide:true,	width, },
			{ label:'备用9', 		name:'user_defined9', 		hide:true,	width, },
			{ label:'备用10', 		name:'user_defined10', 		hide:true,	width, },
		],
	}
	query = {}
	submit = {}
	componentDidMount(){
		
	}
	
	// 点击展开或关闭自定义属性
	customClick = () => {
		const { customHide, formData } = this.state
		this.setState({customHide:!customHide},()=>{
			$fn.hideRows(formData,['user_defined1','user_defined2','user_defined3','user_defined4','user_defined5','user_defined6','user_defined7','user_defined8','user_defined9','user_defined10'], this.state.customHide)
			this.setState({formData})
		})
	}
	
	onForm = () => {
		this.getSelect()
		$http.submit(null,'kd-report-spec/upCaseInfo',{ param:{uuid:$fn.query('uuid')} }).then(data=>{
			this.submit.uuid = data.uuid
			this.formRef.setValue(data)
		})
	}
	
	// 获取下拉数据
	getSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, ['card_type', 'age_first_type', 'age_second_type', 'collect_type'], ()=>{
			$cache.then( async f => {
				const dic = await f.getDicCache({ code: [ 87000, 30000, 45700, 42000 ]})
				// 证件类型
				$fn.setRow( formData, 'card_type', dic['87000'])
				// 年龄类型
				$fn.setRow( formData, 'age_first_type', dic['30000'] )
				$fn.setRow( formData, 'age_second_type', dic['30000'] )
				// 性别
				$fn.setRow( formData, 'sex', dic['45700'] )
				// 受检人类型
				$fn.setRow( formData, 'case_type', dic['42000'] )
				// 采集类型
				$fn.setRow( formData, 'collect_type', f.collect_type )
				this.setState({ formData })
			})
		})
	}
	
	// 操作按钮
	controls = () => [ Controls.back.call(this) ]
	render(){
		const { customHide } = this.state
		return (
			<>
				<Page title='修改基本资料' controls={this.controls()}>
					<div className='ex pt20 mlr20 rel fv wh'>
						{
							SubmitForm.call(this,{
								data:this.state.formData, msg:'保存', scroll:true,api:'kd-report-spec/upCaseInfoData',
								noEsc:true, btnSize:'large', okText:'保存', labelWidth:'s7', hideButton:false, customHide
							}) 
						}
					</div>
				</Page>
			</>
		)
	}
}

export default Index